package com.agileboot.domain.performance.teaching.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.performance.teaching.db.TeachingWorkloadEntity;
import com.agileboot.domain.performance.teaching.db.TeachingWorkloadService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 教学工作量模型工厂
 */
@Component
@RequiredArgsConstructor
public class TeachingWorkloadModelFactory {

    private final TeachingWorkloadService teachingWorkloadService;

    public TeachingWorkloadModel loadById(Long id) {
        TeachingWorkloadEntity entity = teachingWorkloadService.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "教学工作量");
        }
        return new TeachingWorkloadModel(entity, teachingWorkloadService);
    }

    public TeachingWorkloadModel create() {
        return new TeachingWorkloadModel(teachingWorkloadService);
    }

}
